var model = require('../models/authModel'),
  errCode = require('../../conf/errorCode'),
  logger = require('../helper/logger'),
  tagLogger = new logger.TagLogger('AUTH_SERVICE'),
  util = require('../helper/util');

// callback(<integer: errNo>, {userId, accountName}): 鉴权完成时的回调
var checkAuth = (exports.checkAuth = function(accountName, passwd, callback) {
  if (util.isNonemptyStr(accountName) && util.isNonemptyStr(passwd)) {
    model.checkAuth(accountName, util.genPassWd(passwd),callback);
  } else {
    callback({errNo: errCode.LESS_OF_DATA_ERROR}, null);
  }
});

var upsertUser = (exports.upsertUser = function(accountName, callback) {
  if (accountName == null) {
    callback({errNo: errCode.LESS_OF_DATA_ERROR, extraMsgs: '[accountName]'});
    return;
  }
  model.upsertUser(accountName, callback);
});

